home *** CD-ROM | disk | FTP | other *** search
/ Creating Your Own America Online Web Pages / Creating Your Own America Online Web Pages.iso / TOOLS / TEX2RTF / SOURCES.ZIP / SRC / XLPUTILS.CC < prev   
Encoding:
C/C++ Source or Header  |  1994-08-18  |  19.2 KB  |  885 lines

  1. /*
  2.  * xlputils.cc
  3.  *
  4.  * Utility functions for helping convert Latex files
  5.  * into XLP files suitable for compiling into wxHelp
  6.  * files.
  7.  *
  8.  * Julian Smart September 1993
  9.  *
  10.  */
  11.  
  12. #include <wx.h>
  13. #include "tex2any.h"
  14. #include "tex2rtf.h"
  15. #include <ctype.h>
  16.  
  17. long currentBlockId = -1;
  18. static TexChunk *descriptionItemArg = NULL;
  19. static int indentLevel = 0;
  20. static int noColumns = 0;
  21. static int currentTab = 0;
  22. static Bool tableVerticalLineLeft = FALSE;
  23. static Bool tableVerticalLineRight = FALSE;
  24. static Bool inTable = FALSE;
  25. static int citeCount = 1;
  26. wxList hyperLinks(wxKEY_INTEGER);
  27. wxList hyperLabels(wxKEY_STRING);
  28. FILE *Index = NULL;
  29.  
  30. void PadToTab(int tabPos)
  31. {
  32.   int currentCol = GetCurrentColumn();
  33.   for (int i = currentCol; i < tabPos; i++)
  34.     TexOutput(" ", TRUE);
  35. }
  36.  
  37. static long xlpBlockId = 0;
  38. long NewBlockId(void)
  39. {
  40.   return xlpBlockId ++;
  41. }
  42.  
  43. // Called on start/end of macro examination
  44. void XLPOnMacro(int macroId, int no_args, Bool start)
  45. {
  46.   char buf[100];
  47.   switch (macroId)
  48.   {
  49.   case ltCHAPTER:
  50.   case ltCHAPTERSTAR:
  51.   case ltCHAPTERHEADING:
  52.   {
  53.     if (!start)
  54.     {
  55.       sectionNo = 0;
  56.       figureNo = 0;
  57.       subsectionNo = 0;
  58.       subsubsectionNo = 0;
  59.       if (macroId != ltCHAPTERSTAR)
  60.         chapterNo ++;
  61.  
  62.       SetCurrentOutputs(Contents, Chapters);
  63.       long id1 = NewBlockId();
  64.       currentBlockId = NewBlockId();
  65.  
  66.       startedSections = TRUE;
  67.       fprintf(Contents, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, id1);
  68.       fprintf(Chapters, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
  69.       fprintf(Index, "%ld %ld\n", id1, currentBlockId);
  70.  
  71.       OutputCurrentSection(); // Repeat section header
  72.  
  73.       fprintf(Contents, "}\n\n");
  74.       fprintf(Chapters, "}\n\n");
  75.       SetCurrentOutput(Chapters);
  76.       char *topicName = FindTopicName(GetNextChunk());
  77.       hyperLabels.Append(topicName, (wxObject *)currentBlockId);
  78.     }
  79.     break;
  80.   }
  81.   case ltSECTION:
  82.   case ltSECTIONSTAR:
  83.   case ltSECTIONHEADING:
  84.   case ltGLOSS:
  85.   {
  86.     if (!start)
  87.     {
  88.       subsectionNo = 0;
  89.       subsubsectionNo = 0;
  90.  
  91.       if (macroId != ltSECTIONSTAR)
  92.         sectionNo ++;
  93.         
  94.       SetCurrentOutputs(Chapters, Sections);
  95.       long id1 = NewBlockId();
  96.       currentBlockId = NewBlockId();
  97.  
  98.       startedSections = TRUE;
  99.  
  100.       if (DocumentStyle == LATEX_ARTICLE)
  101.         fprintf(Contents, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, id1);
  102.       else
  103.         fprintf(Chapters, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1);
  104.       fprintf(Sections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
  105.       fprintf(Index, "%ld %ld\n", id1, currentBlockId);
  106.  
  107.       OutputCurrentSection(); // Repeat section header
  108.  
  109.       if (DocumentStyle == LATEX_ARTICLE)
  110.         fprintf(Contents, "}\n\n");
  111.       else
  112.         fprintf(Chapters, "}\n\n");
  113.       fprintf(Sections, "}\n\n");
  114.       SetCurrentOutput(Sections);
  115.       char *topicName = FindTopicName(GetNextChunk());
  116.       hyperLabels.Append(topicName, (wxObject *)currentBlockId);
  117.     }
  118.     break;
  119.   }
  120.   case ltSUBSECTION:
  121.   case ltSUBSECTIONSTAR:
  122.   case ltMEMBERSECTION:
  123.   case ltFUNCTIONSECTION:
  124.   {
  125.     if (!start)
  126.     {
  127.       subsubsectionNo = 0;
  128.  
  129.       if (macroId != ltSUBSECTIONSTAR)
  130.         subsectionNo ++;
  131.  
  132.       SetCurrentOutputs(Sections, Subsections);
  133.       long id1 = NewBlockId();
  134.       currentBlockId = NewBlockId();
  135.       fprintf(Sections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1);
  136.       fprintf(Subsections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
  137.       fprintf(Index, "%ld %ld\n", id1, currentBlockId);
  138.  
  139.       OutputCurrentSection(); // Repeat section header
  140.  
  141.       fprintf(Sections, "}\n\n");
  142.       fprintf(Subsections, "}\n\n");
  143.       SetCurrentOutput(Subsections);
  144.       char *topicName = FindTopicName(GetNextChunk());
  145.       hyperLabels.Append(topicName, (wxObject *)currentBlockId);
  146.     }
  147.     break;
  148.   }
  149.   case ltSUBSUBSECTION:
  150.   case ltSUBSUBSECTIONSTAR:
  151.   {
  152.     if (!start)
  153.     {
  154.       if (macroId != ltSUBSUBSECTIONSTAR)
  155.         subsubsectionNo ++;
  156.  
  157.       SetCurrentOutputs(Subsections, Subsubsections);
  158.       long id1 = NewBlockId();
  159.       currentBlockId = NewBlockId();
  160.       fprintf(Subsections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1);
  161.       fprintf(Subsubsections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
  162.       fprintf(Index, "%ld %ld\n", id1, currentBlockId);
  163.  
  164.       OutputCurrentSection(); // Repeat section header
  165.  
  166.       fprintf(Subsections, "}\n\n");
  167.       fprintf(Subsubsections, "}\n\n");
  168.       SetCurrentOutput(Subsubsections);
  169.       char *topicName = FindTopicName(GetNextChunk());
  170.       hyperLabels.Append(topicName, (wxObject *)currentBlockId);
  171.     }
  172.     break;
  173.   }
  174.   case ltFUNC:
  175.   case ltPFUNC:
  176.   case ltMEMBER:
  177.   {
  178.     SetCurrentOutput(Subsections);
  179.     if (start)
  180.     {
  181.       long id = NewBlockId();
  182.       fprintf(Subsections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id);
  183.     }
  184.     else
  185.       fprintf(Subsections, "}");
  186.     break;
  187.   }
  188.   case ltVOID:
  189.     if (start)
  190.       TexOutput("void", TRUE);
  191.     break;
  192.   case ltBACKSLASHCHAR:
  193.     if (start)
  194.       TexOutput("\n", TRUE);
  195.     break;
  196.   case ltPAR:
  197.   {
  198.     if (start)
  199.     {
  200.       if (ParSkip > 0)
  201.         TexOutput("\n", TRUE);
  202.       TexOutput("\n", TRUE);
  203.     }
  204.     break;
  205.   }
  206.   case ltBF:
  207.   {
  208.     if (start)
  209.     {
  210.       char buf[100];
  211.       long id = NewBlockId();
  212.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id);
  213.       TexOutput(buf);
  214.     }
  215.     else TexOutput("}");
  216.     break;
  217.   }
  218.   case ltIT:
  219.   {
  220.     if (start)
  221.     {
  222.       char buf[100];
  223.       long id = NewBlockId();
  224.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_ITALIC, id);
  225.       TexOutput(buf);
  226.     }
  227.     else TexOutput("}");
  228.     break;
  229.   }
  230.   case ltTT:
  231.   {
  232.     if (start)
  233.     {
  234.       long id = NewBlockId();
  235.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, id);
  236.       TexOutput(buf);
  237.     }
  238.     else TexOutput("}");
  239.     break;
  240.   }
  241.   case ltSMALL:
  242.   {
  243.     if (start)
  244.     {
  245.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_TEXT, NewBlockId());
  246.       TexOutput(buf);
  247.     }
  248.     else TexOutput("}");
  249.     break;
  250.   }
  251.   case ltTINY:
  252.   {
  253.     if (start)
  254.     {
  255.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_TEXT, NewBlockId());
  256.       TexOutput(buf);
  257.     }
  258.     else TexOutput("}");
  259.     break;
  260.   }
  261.   case ltNORMALSIZE:
  262.   {
  263.     if (start)
  264.     {
  265.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_NORMAL, NewBlockId());
  266.       TexOutput(buf);
  267.     }
  268.     else TexOutput("}");
  269.     break;
  270.   }
  271.   case ltlarge:
  272.   {
  273.     if (start)
  274.     {
  275.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, NewBlockId());
  276.       TexOutput(buf);
  277.     }
  278.     else TexOutput("}\n");
  279.     break;
  280.   }
  281.   case ltLARGE:
  282.   {
  283.     if (start)
  284.     {
  285.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, NewBlockId());
  286.       TexOutput(buf);
  287.     }
  288.     else TexOutput("}\n");
  289.     break;
  290.   }
  291.   case ltITEMIZE:
  292.   case ltENUMERATE:
  293.   case ltDESCRIPTION:
  294.   case ltTWOCOLLIST:
  295.   {
  296.     if (start)
  297.     {
  298. //      tabCount ++;
  299.  
  300. //      if (indentLevel > 0)
  301. //        TexOutput("\\par\\par\n");
  302.       indentLevel ++;
  303.       int listType;
  304.       if (macroId == ltENUMERATE)
  305.         listType = LATEX_ENUMERATE;
  306.       else if (macroId == ltITEMIZE)
  307.         listType = LATEX_ITEMIZE;
  308.       else
  309.         listType = LATEX_DESCRIPTION;
  310.       itemizeStack.Insert(new ItemizeStruc(listType));
  311.  
  312.     }
  313.     else
  314.     {
  315.       indentLevel --;
  316.  
  317.       if (itemizeStack.First())
  318.       {
  319.         ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
  320.         delete struc;
  321.         delete itemizeStack.First();
  322.       }
  323.     }
  324.     break;
  325.   }
  326.   case ltITEM:
  327.   {
  328.     wxNode *node = itemizeStack.First();
  329.     if (node)
  330.     {
  331.       ItemizeStruc *struc = (ItemizeStruc *)node->Data();
  332.       if (!start)
  333.       {
  334.         struc->currentItem += 1;
  335.         char indentBuf[30];
  336.  
  337.         switch (struc->listType)
  338.         {
  339.           case LATEX_ENUMERATE:
  340.           {
  341.             sprintf(indentBuf, "\\hy-%d{%ld}{%d.} ",
  342.               hyBLOCK_BOLD, NewBlockId(), struc->currentItem);
  343.             TexOutput(indentBuf);
  344.             break;
  345.           }
  346.           case LATEX_ITEMIZE:
  347.           {
  348.             sprintf(indentBuf, "\\hy-%d{%ld}{o} ",
  349.               hyBLOCK_BOLD, NewBlockId());
  350.             TexOutput(indentBuf);
  351.             break;
  352.           }
  353.           default:
  354.           case LATEX_DESCRIPTION:
  355.           {
  356.             if (descriptionItemArg)
  357.             {
  358.               sprintf(indentBuf, "\\hy-%d{%ld}{",
  359.                  hyBLOCK_BOLD, NewBlockId());
  360.               TexOutput(indentBuf);
  361.               TraverseChildrenFromChunk(descriptionItemArg);
  362.               TexOutput("} ");
  363.               descriptionItemArg = NULL;
  364.             }
  365.             break;
  366.           }
  367.     }
  368.       }
  369.     }
  370.     break;
  371.   }
  372.   case ltMAKETITLE:
  373.   {
  374.     if (start && DocumentTitle && DocumentAuthor)
  375.     {
  376.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, NewBlockId());
  377.       TexOutput(buf);
  378.       TraverseChildrenFromChunk(DocumentTitle);
  379.       TexOutput("}\n\n");
  380.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, NewBlockId());
  381.       TexOutput(buf);
  382.       TraverseChildrenFromChunk(DocumentAuthor);
  383.       TexOutput("}\n\n");
  384.       if (DocumentDate)
  385.       {
  386.         TraverseChildrenFromChunk(DocumentDate);
  387.         TexOutput("\n");
  388.       }
  389.     }
  390.     break;
  391.   }
  392.   case ltTABLEOFCONTENTS:
  393.   {
  394.     if (start)
  395.     {
  396.       FILE *fd = fopen(ContentsName, "r");
  397.       if (fd)
  398.       {
  399.         char ch = getc(fd);
  400.         while (ch != EOF)
  401.         {
  402.           putc(ch, Chapters);
  403.           ch = getc(fd);
  404.         }
  405.         fclose(fd);
  406.       }
  407.       else
  408.       {
  409.         TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
  410.         OnInform("Run Tex2RTF again to include contents page.");
  411.       }
  412.     }
  413.     break;
  414.   }
  415.   case ltHARDY:
  416.   {
  417.     if (start)
  418.       TexOutput("HARDY", TRUE);
  419.     break;
  420.   }
  421.   case ltWXCLIPS:
  422.   {
  423.     if (start)
  424.       TexOutput("wxCLIPS", TRUE);
  425.     break;
  426.   }
  427.   case ltVERBATIM:
  428.   {
  429.     if (start)
  430.     {
  431.       char buf[100];
  432.       long id = NewBlockId();
  433.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, id);
  434.       TexOutput(buf);
  435.     }
  436.     else TexOutput("}");
  437.     break;
  438.   }
  439.   case ltHRULE:
  440.   {
  441.     if (start)
  442.     {
  443.       TexOutput("\n------------------------------------------------------------------", TRUE);
  444.     }
  445.     break;
  446.   }
  447.   case ltHLINE:
  448.   {
  449.     if (start)
  450.     {
  451.       TexOutput("--------------------------------------------------------------------------------", TRUE);
  452.     }
  453.     break;
  454.   }
  455.   case ltSPECIALAMPERSAND:
  456.   {
  457.     if (start)
  458.     {
  459.       currentTab ++;
  460.       int tabPos = (80/noColumns)*currentTab;
  461.       PadToTab(tabPos);
  462.     }
  463.     break;
  464.   }
  465.   case ltTABULAR:
  466.   case ltSUPERTABULAR:
  467.   {
  468.     if (start)
  469.     {
  470.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, NewBlockId());
  471.       TexOutput(buf);
  472.     }
  473.     else
  474.       TexOutput("}");
  475.     break;
  476.   }
  477.   case ltNUMBEREDBIBITEM:
  478.   {
  479.     if (!start)
  480.       TexOutput("\n\n", TRUE);
  481.     break;
  482.   }
  483.   case ltCAPTION:
  484.   case ltCAPTIONSTAR:
  485.   {
  486.     if (start)
  487.     {
  488.       figureNo ++;
  489.  
  490.       char figBuf[40];
  491.       if (DocumentStyle != LATEX_ARTICLE)
  492.         sprintf(figBuf, "Figure %d.%d: ", chapterNo, figureNo);
  493.       else
  494.         sprintf(figBuf, "Figure %d: ", figureNo);
  495.  
  496.       TexOutput(figBuf);
  497.     }
  498.     else
  499.     {
  500.       char *topicName = FindTopicName(GetNextChunk());
  501.  
  502.       AddTexRef(topicName, NULL, NULL,
  503.            ((DocumentStyle != LATEX_ARTICLE) ? chapterNo : figureNo),
  504.             ((DocumentStyle != LATEX_ARTICLE) ? figureNo : 0));
  505.     }
  506.     break;
  507.   }
  508.   default:
  509.   {
  510.     DefaultOnMacro(macroId, no_args, start);
  511.     break;
  512.   }
  513.   }
  514. }
  515.  
  516. Bool XLPOnArgument(int macroId, int arg_no, Bool start)
  517. {
  518.   char buf[300];
  519.   switch (macroId)
  520.   {
  521.   case ltCHAPTER:
  522.   case ltCHAPTERSTAR:
  523.   case ltCHAPTERHEADING:
  524.   case ltSECTION:
  525.   case ltSECTIONSTAR:
  526.   case ltSECTIONHEADING:
  527.   case ltSUBSECTION:
  528.   case ltSUBSECTIONSTAR:
  529.   case ltSUBSUBSECTION:
  530.   case ltSUBSUBSECTIONSTAR:
  531.   case ltGLOSS:
  532.   case ltMEMBERSECTION:
  533.   case ltFUNCTIONSECTION:
  534.   {
  535.     if (!start && (arg_no == 1))
  536.       currentSection = GetArgChunk();
  537.     return FALSE;
  538.     break;
  539.   }
  540.   case ltFUNC:
  541.   {
  542.     if (!start && (arg_no == 1))
  543.       TexOutput(" ", TRUE);
  544.     if (start && (arg_no == 3))
  545.       TexOutput("(", TRUE);
  546.     if (!start && (arg_no == 3))
  547.      TexOutput(")", TRUE);
  548.     break;
  549.   }
  550.   case ltPFUNC:
  551.   {
  552.     if (!start && (arg_no == 1))
  553.       TexOutput(" ", TRUE);
  554.  
  555.     if (start && (arg_no == 2))
  556.       TexOutput("(*", TRUE);
  557.     if (!start && (arg_no == 2))
  558.       TexOutput(")", TRUE);
  559.  
  560.     if (start && (arg_no == 3))
  561.       TexOutput("(", TRUE);
  562.     if (!start && (arg_no == 3))
  563.       TexOutput(")", TRUE);
  564.     break;
  565.   }
  566.   case ltCLIPSFUNC:
  567.   {
  568.     if (!start && (arg_no == 1))
  569.       TexOutput(" ", TRUE);
  570.     if (start && (arg_no == 2))
  571.     {
  572.       TexOutput("(", TRUE);
  573.       long id = NewBlockId();
  574.       sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id);
  575.       TexOutput(buf);
  576.     }
  577.     if (!start && (arg_no == 2))
  578.     {
  579.       TexOutput("}");
  580.     }
  581.     if (!start && (arg_no == 3))
  582.      TexOutput(")", TRUE);
  583.     break;
  584.   }
  585.   case ltPARAM:
  586.   {
  587.     if (start && (arg_no == 2))
  588.     {
  589.       long id = NewBlockId();
  590.       sprintf(buf, " \\hy-%d{%ld}{", hyBLOCK_BOLD, id);
  591.       TexOutput(buf);
  592.     }
  593.     if (!start && (arg_no == 2))
  594.     {
  595.       TexOutput("}");
  596.     }
  597.     break;
  598.   }
  599.   case ltCPARAM:
  600.   {
  601.     if (start && (arg_no == 2))
  602.     {
  603.       long id = NewBlockId();
  604.       sprintf(buf, " \\hy-%d{%ld}{", hyBLOCK_BOLD, id);
  605.       TexOutput(buf);
  606.     }
  607.     if (!start && (arg_no == 2))
  608.     {
  609.       TexOutput("}");
  610.     }
  611.     break;
  612.   }
  613.   case ltMEMBER:
  614.   {
  615.     if (!start && (arg_no == 1))
  616.       TexOutput(" ", TRUE);
  617.     break;
  618.   }
  619.   case ltLABEL:
  620.   {
  621.     return FALSE;
  622.     break;
  623.   }
  624.   case ltREF:
  625.   {
  626.     if (start)
  627.     {
  628.       char *sec = NULL;
  629.       
  630.       char *refName = GetArgData();
  631.       if (refName)
  632.       {
  633.         TexRef *texRef = FindReference(refName);
  634.         if (texRef)
  635.         {
  636.           sec = texRef->sectionNumber;
  637.         }
  638.       }
  639.       if (sec)
  640.       {
  641.         TexOutput(sec);
  642.       }
  643.       return FALSE;
  644.     }
  645.     break;
  646.   }
  647.   case ltHELPREF:
  648.   case ltHELPREFN:
  649.   case ltPOPREF:
  650.   {
  651.     if (arg_no == 1)
  652.     {
  653.       if (start)
  654.       {
  655.         currentBlockId = NewBlockId();
  656.         sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_RED_ITALIC, currentBlockId);
  657.         TexOutput(buf);
  658.       }
  659.       else TexOutput("}");
  660.     }
  661.     if (arg_no == 2)
  662.     {
  663.       if (start)
  664.       {
  665.         char *label = GetArgData();
  666.         hyperLinks.Append(currentBlockId, (wxObject *)copystring(label));
  667.       }
  668.       
  669.       return FALSE;
  670.     }
  671.     break;
  672.   }
  673.   case ltITEM:
  674.   {
  675.     if (start && IsArgOptional())
  676.     {
  677.       descriptionItemArg = GetArgChunk();
  678.       return FALSE;
  679.     }
  680.     break;
  681.   }
  682.   case ltTABULAR:
  683.   case ltSUPERTABULAR:
  684.   {
  685.     if (arg_no == 1)
  686.     {
  687.       if (start)
  688.       {
  689.         inTable = TRUE;
  690.         tableVerticalLineLeft = FALSE;
  691.         tableVerticalLineRight = FALSE;
  692.  
  693.         char *alignString = copystring(GetArgData());
  694.  
  695.         // Count the number of columns
  696.         noColumns = 0;
  697.         int len = strlen(alignString);
  698.         if (len > 0)
  699.         {
  700.           if (alignString[0] == '|')
  701.             tableVerticalLineLeft = TRUE;
  702.           if (alignString[len-1] == '|')
  703.             tableVerticalLineRight = TRUE;
  704.         }
  705.  
  706.         for (int i = 0; i < len; i++)
  707.           if (isalpha(alignString[i]))
  708.             noColumns ++;
  709.  
  710. /*
  711.       // Experimental
  712.       TexOutput("\\brdrt\\brdrs");
  713.       if (tableVerticalLineLeft)
  714.         TexOutput("\\brdrl\\brdrs");
  715.       if (tableVerticalLineRight)
  716.         TexOutput("\\brdrr\\brdrs");
  717. */
  718.  
  719.         // Calculate a rough size for each column
  720. //        int tabPos = 80/noColumns;
  721.         currentTab = 0;
  722.  
  723.         return FALSE;
  724.       }
  725.     }
  726.     else if (arg_no == 2 && !start)
  727.     {
  728.       inTable = FALSE;
  729.     }
  730.     else if (arg_no == 2 && start)
  731.       return TRUE;
  732.     break;
  733.   }
  734.   case ltMARGINPAR:
  735.   case ltMARGINPAREVEN:
  736.   case ltMARGINPARODD:
  737.   case ltNORMALBOX:
  738.   case ltNORMALBOXD:
  739.   {
  740.     if (start)
  741.     {
  742.       TexOutput("----------------------------------------------------------------------\n", TRUE);
  743.       return TRUE;
  744.     }
  745.     else
  746.       TexOutput("\n----------------------------------------------------------------------\n", TRUE);
  747.     break;
  748.   }
  749.   case ltBIBITEM:
  750.   {
  751.     char buf[100];
  752.     if (arg_no == 1 && start)
  753.     {
  754.       char *citeKey = GetArgData();
  755.       TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
  756.       if (ref)
  757.       {
  758.         if (ref->sectionNumber) delete[] ref->sectionNumber;
  759.         sprintf(buf, "[%d]", citeCount);
  760.         ref->sectionNumber = copystring(buf);
  761.       }
  762.  
  763.       sprintf(buf, "\\hy-%d{%ld}{[%d]} ", hyBLOCK_BOLD, NewBlockId(), citeCount);
  764.       TexOutput(buf);
  765.       citeCount ++;
  766.       return FALSE;
  767.     }
  768.     return TRUE;
  769.     break;
  770.   }
  771.   case ltTHEBIBLIOGRAPHY:
  772.   {
  773.     if (start && (arg_no == 1))
  774.     {
  775.       citeCount = 1;
  776.  
  777.       SetCurrentOutput(Chapters);
  778.  
  779.       SetCurrentOutputs(Contents, Chapters);
  780.       long id1 = NewBlockId();
  781.       long id2 = NewBlockId();
  782.       fprintf(Contents, "\\hy-%d{%ld}{%s}\n", hyBLOCK_SMALL_HEADING, id1, ReferencesNameString);
  783.       fprintf(Chapters, "\\hy-%d{%ld}{%s}\n\n\n", hyBLOCK_LARGE_VISIBLE_SECTION, id2, ReferencesNameString);
  784.       fprintf(Index, "%ld %ld\n", id1, id2);
  785.  
  786.       SetCurrentOutput(Chapters);
  787.       return FALSE;
  788.     }
  789.     if (!start && (arg_no == 2))
  790.     {
  791.     }
  792.     return TRUE;
  793.     break;
  794.   }
  795.   case ltTWOCOLITEM:
  796.   case ltTWOCOLITEMRULED:
  797.   {
  798.     if (start && (arg_no == 2))
  799.       TexOutput("\n    ");
  800.  
  801.     if (!start && (arg_no == 2))
  802.       TexOutput("\n");
  803.     return TRUE;
  804.   }
  805.   default:
  806.   {
  807.     return DefaultOnArgument(macroId, arg_no, start);
  808.     break;
  809.   }
  810.   }
  811.   return TRUE;
  812. }
  813.  
  814. Bool XLPGo(void)
  815. {
  816.   xlpBlockId = 0;
  817.  
  818.   if (InputFile && OutputFile)
  819.   {
  820.     Contents = fopen(TmpContentsName, "w");
  821.     Chapters = fopen("chapters.xlp", "w");
  822.     Sections = fopen("sections.xlp", "w");
  823.     Subsections = fopen("subsections.xlp", "w");
  824.     Subsubsections = fopen("subsubsections.xlp", "w");
  825.     Index = fopen("index.xlp", "w");
  826.  
  827.     // Insert invisible section marker at beginning
  828.     fprintf(Chapters, "\\hy-%d{%ld}{%s}\n",
  829.                 hyBLOCK_INVISIBLE_SECTION, NewBlockId(), "\n");
  830.  
  831.     fprintf(Contents, "\\hy-%d{%ld}{%s}\n\n",
  832. //                hyBLOCK_LARGE_HEADING, NewBlockId(), "\n\n%s\n\n", ContentsNameString);
  833.                 hyBLOCK_LARGE_HEADING, NewBlockId(), ContentsNameString);
  834.  
  835.     SetCurrentOutput(Chapters);
  836.  
  837.     fprintf(Index, "\n\\hyindex{\n\"%s\"\n",
  838.              contentsString ? contentsString : "WXHELPCONTENTS");
  839.     TraverseDocument();
  840.  
  841.     wxNode *node = hyperLinks.First();
  842.     while (node)
  843.     {
  844.       long from = node->key.integer;
  845.       char *label = (char *)node->Data();
  846.       wxNode *otherNode = hyperLabels.Find(label);
  847.       if (otherNode)
  848.       {
  849.         long to = (long)otherNode->Data();
  850.         fprintf(Index, "%ld %ld\n", from, to);
  851.       }
  852.       node = node->Next();
  853.     }
  854.  
  855.     fprintf(Index, "}\n");
  856.  
  857.     fclose(Contents);
  858.     fclose(Chapters);
  859.     fclose(Sections);
  860.     fclose(Subsections);
  861.     fclose(Subsubsections);
  862.     fclose(Index);
  863.  
  864.     if (FileExists(ContentsName)) wxRemoveFile(ContentsName);
  865.     wxRenameFile(TmpContentsName, ContentsName);
  866.  
  867.     wxConcatFiles("chapters.xlp", "sections.xlp", "tmp2.xlp");
  868.     wxConcatFiles("tmp2.xlp", "subsections.xlp", "tmp1.xlp");
  869.     wxConcatFiles("tmp1.xlp", "subsubsections.xlp", "tmp2.xlp");
  870.     wxConcatFiles("tmp2.xlp", "index.xlp", OutputFile);
  871.  
  872.     wxRemoveFile("tmp1.xlp");
  873.     wxRemoveFile("tmp2.xlp");
  874.  
  875.     wxRemoveFile("chapters.xlp");
  876.     wxRemoveFile("sections.xlp");
  877.     wxRemoveFile("subsections.xlp");
  878.     wxRemoveFile("subsubsections.xlp");
  879.     wxRemoveFile("index.xlp");
  880.     return TRUE;
  881.   }
  882.   return FALSE;
  883. }
  884.  
  885.